package team.fjut.cf.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import team.fjut.cf.mapper.ProblemAnalysisMapper;
import team.fjut.cf.pojo.po.ProblemAanalysisPO;
import team.fjut.cf.pojo.vo.ProblemAnalysisPreviewVO;
import team.fjut.cf.service.ProblemAnalysisService;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
//申明这个类是业务层
public class ProblemAnalysisServiceImpl implements ProblemAnalysisService {
    @Resource
    ProblemAnalysisMapper problemAnalysisMapper;


    public Integer insertProblemAnalysis(String title, String Content,String author,Integer problemId){

        Date time = new Date();//获取时间
        String preview = Content.substring(0,25);

        ProblemAanalysisPO problemAanalysisPO = new ProblemAanalysisPO();
        problemAanalysisPO.setTitle(title);
        problemAanalysisPO.setContent(Content);
        problemAanalysisPO.setAuthor(author);
        problemAanalysisPO.setPreview(preview);
        problemAanalysisPO.setTime(time);
        problemAanalysisPO.setProblemId(problemId);

        return problemAnalysisMapper.insertSelective(problemAanalysisPO);
    }

    public List<ProblemAnalysisPreviewVO> selectProblemAnalysisPreview(Integer pageNum,Integer pageSize,Integer problemId,String title){
        PageHelper.startPage(pageNum, pageSize);
        return problemAnalysisMapper.selectProblemAnalysisPreview(problemId,title);
    }

    public int countProblemAnalysisPreview(Integer problemId,String title){
        return problemAnalysisMapper.countProblemAnalysisPreview(problemId,title);
    }

    public ProblemAanalysisPO selectProblemAnalysisInfo(Integer id){
        ProblemAanalysisPO problemAanalysisPO = new ProblemAanalysisPO();
        problemAanalysisPO.setId(id);
        return problemAnalysisMapper.selectOne(problemAanalysisPO);
    }
}
